package com.ddwl.wallet.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.wallet.DistOrderVo;
import com.ddwl.wallet.service.OrderRefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * 类DistOrderController.java的实现描述：佣金订单退款接口
 *
 * @author zach
 * @Date :2020-07-22 17:41.
 */
@Slf4j
@Api(tags = "佣金订单退款接口")
@RequestMapping("dist/order/refund")
@RestController
public class DistOrderRefundController extends BaseController {

    @Resource
    private OrderRefundService orderRefundService;


    @PostMapping("/cre")
    @Auth(product =  BaseEnum.ProductEnum.API)
    @ApiOperation("创建退款信息")
    public RestVo createOrderRefundAmount(@RequestParam String orderId, String spuId, @RequestParam BigDecimal refundAmount,@RequestParam String refundId,@RequestParam Integer skuQty) {
        orderRefundService.createOrderRefundAmount(orderId,spuId,refundAmount,refundId,skuQty);
        return RestVo.ok();
    }


    @PostMapping("/submit")
    @Auth(product = {BaseEnum.ProductEnum.API})
    @ApiOperation("提交退款")
    public RestVo<PageVo<DistOrderVo>> submitOrderRefund(@RequestParam String orderId, String spuId, @RequestParam BigDecimal refundAmount, @RequestParam String refundId, @RequestParam Integer skuQty) {
        orderRefundService.submitOrderRefundAmount(orderId,spuId,refundAmount,refundId,skuQty);
        return RestVo.ok();
    }

    @PostMapping("/cancel")
    @Auth(product = {BaseEnum.ProductEnum.API})
    @ApiOperation("取消退款")
    public RestVo<PageVo<DistOrderVo>> cancel(@RequestParam String refundId) {
        orderRefundService.cancelOrderRefundAmount(refundId);
        return RestVo.ok();
    }

    @PostMapping("/complete")
    @Auth(product = {BaseEnum.ProductEnum.API})
    @ApiOperation("完成退款")
    public RestVo orderDistFinishNew(@RequestParam String refundId) {
        orderRefundService.completeOrderRefundAmount(refundId);
        return RestVo.ok();
    }

}
